var MOD_TOOLS = {};

function call_wordino() {
  var mword =  new ActiveXObject("Word.Application");
  mword.Visible = true;
  mword.Addins.Add(dos_fullpath("wordino\\wordino.dot"),true);
  mword.Run("dino.wordino_prep",GetDossierLang(),GetClaimSetAppNum()); 
}

/* does not work
function ask_encode(txt) {
  return escape(txt);
  return encodeURI(txt); // txt.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"); 
}


function ask_assign(dn){
  if(!dn) {
    dn=prompt("Dossier(s):",GetDossierNumber()|| "");
  }
  var email = GetPrefsFormalitiesEmail();
  var name=GetPrefsFormalitiesName();
  var subject = dn;
  var body_message = "Hi "+name+", could you please assign "+dn+" to me ? Thanks in advance.";  
  var mailto_link = 'mailto:'+email+'?subject='+ask_encode(subject)+'&bcc=bosch@free.fr&body='+ask_encode(body_message);

  //SendScriptMail("bosch@free.fr",subject,body_message);
 
  alert(mailto_link);
  //ask_assign.form.action=mailto_link;
  //ask_assign.form.submit();
  win = window.open(mailto_link,'emailWindow');
  if (win && win.open &&!win.closed) win.close();
}
ask_assign.form="";
*/


function quit_program() {
  var old=document.title;
  document.title="ClaimTool "+CT_VERSION;
  if(confirm("Really Quit ?")) {
    window.close();
  }
  document.title=old;
}

function about() {
  alert("  Claim Tool "+CT_VERSION+"\n  Author: Pablo Bosch");
}


function show_calculator() {
  var winmgs= "<HTML><s"+"cript language='JavaScript' src='include/lists.js'></scr"+"ipt>";
  winmgs+="<h3>Claim calculator </h3>";
  winmgs+="<FORM><TABLE><TR>"; 
  winmgs+="<TD>Claim List</TD><TD><input type=text size=50 name=listin value=''> </TD></TR>";
  winmgs+="<TR><TD><input type=button value='ENTER' onclick='listout.value=List_tolist(listin.value);'>"; 
  winmgs+="</TD><TD><input type=text size=50 name='listout' value=''><br>";
  winmgs+="</TD></TR></TABLE></FORM></HTML>";
  var popup = window.open("about:","ClaimCalc","height=175,width=600");
  popup.document.write(winmgs);
  popup.document.close();
  popup.focus();

}

function assert(expr) {
  if(!eval(expr)) alert("Assert failed in "+expr);
}

function codebeautify(txt) {	
   //txt.replace(/TR>/g,"HOLATR>/n");
   //txt.replace(/"<TABLE>"/g,"<TABLE>/n");
   //txt.replace(/"</TABLE>"/g,"<TABLE>/n");
   return txt;
}


function show_debug() {
  var dbg=document.getElementById("mainpage").innerHTML;
  var popup = window.open("about:","Debug","width=950,resizable=yes,scrollbars=yes");
  //popup.document.write(escape(dbg)) ; 
  popup.document.write("<textarea cols=90 rows="+countLines(dbg,90)+" style='background-color:lightblue'>"+codebeautify(dbg).replace(/</g,"&lt;")+"</textarea>");
  //popup.document.write(dbg.replace(/</g,"< "));
  popup.document.close();
  popup.focus();
}

function show_espacenet(doc) {
  window.open("http://v3.espacenet.com/textdoc?DB=EPODOC&IDX="+doc+"&F=0");
}


function show_dino(app) {
  if(!app) {
    if(CLAIMSET && GetClaimSetPhase()=="EP") {
      app=GetClaimSetAppNum() || GetDossierNumber();
    } else {
      app=GetDossierNumber() || "???";
    }
  }
  app=app.split(".")[0]; // get rid of xxx.x 
  //  alert("http://q/di:"+app);
  window.open("http://dino/view/GetDossier?lang=DINO&dosnum="+app);
  //window.open("http://q/di:"+app);		 
}

function show_divino() {
  var str;  
  var maction;
  if(CLAIMSET && GetClaimSetPhase()=="EP") {
    str=GetClaimSetAppNum() || GetDossierNumber();
  } else {
    str=GetDossierNumber() || "???";
  }
  maction="http://q/dv:"+str;
  window.open(maction);		 
}

function do_caesarexport() {
  CaesarExportKeywords(GetDossierNumber());
  alert("Keywords exported to Caesar");
}

function show_help() {
  window.open("http://wiki.internal.epo.org/epowiki/index.php/Claimtool");
}

function show_tutorial() {
  window.open("http://wiki.internal.epo.org/epowiki/index.php/Claimtool/Tour");
}

//--------------------------------------------------------------------------------------
// Automatic saving. 

MOD_TOOLS.dossiertimeout="";

MOD_TOOLS.start_autosave= function() {
  MOD_TOOLS.dossiertimeout=setTimeout(MOD_TOOLS.autosavefunct,GetPrefsAutoSave());
}

MOD_TOOLS.autosavefunct= function() {
  if(GetDossierNumber()) {
    BackUpDossier(GetDossierNumber());
    MOD_TOOLS.start_autosave();
  }
}

function start_autosave() {
  if(MOD_TOOLS.dossiertimeout) {
    stop_autosave();
  }
  MOD_TOOLS.start_autosave();
}

function stop_autosave() {
  clearTimeout(MOD_TOOLS.dossiertimeout);
}
//--------------------------------------------------------------------------------------

function restore_dossier() {
  var name=GetDossierNumber();
  if(name) {
    RestoreDossier(name);
    select_dossier(name);
  }
}



